import grpc
import calculator_pb2
import calculator_pb2_grpc

def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = calculator_pb2_grpc.CalculatorStub(channel)
    
    # 简单调用
    response = stub.Add(calculator_pb2.AddRequest(a=10, b=20))
    print(f"10 + 20 = {response.result}")
    
    # 交互式调用
    while True:
        try:
            a = int(input("Enter first number: "))
            b = int(input("Enter second number: "))
            response = stub.Add(calculator_pb2.AddRequest(a=a, b=b))
            print(f"Result: {response.result}")
        except KeyboardInterrupt:
            print("\nExiting...")
            break

if __name__ == '__main__':
    run()